import axios from 'axios';
import { base_url } from '../config';

export const user = {
    /*
     * 新增用户接口
     * 调用这个接口需要提前判断字段是否齐全
     * userInfo.username
     * userInfo.workId
     * userInfo.facultyId
     * userInfo.phone
     * userInfo.password
     * userInfo.email
     * userInfo.userType
     * userInfo.allowLogin
     * 这些都是必须字段
     */
    async addUser(jwt: string, userInfo: any) {
        try {
            const response = await axios.post(base_url + '/users/addUser', userInfo, {
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': jwt
                }
            });
            const data = response.data;
            console.log('【resposeData: in function addUser】', data);
            return { success: true, data: data };
        } catch (err) {
            console.log('【err: in function addUser】', err);
            return { success: false, err: err };
        }
    },